package com.pro.common.service.admin.model.db;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.pro.common.api.CommonConst;
import com.pro.common.service.admin.enums.*;
import com.pro.framework.api.enums.IEnumToDbDbId;
import com.pro.framework.api.model.IdModel;
import com.pro.framework.api.model.IdsModel;
import com.pro.framework.javatodb.annotation.JTDField;
import com.pro.framework.javatodb.annotation.JTDTable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@Schema(description = "调度任务信息")
@JTDTable(entityId = 10010, module = CommonConst.Modules.admin,
        sequences = {"KEY job_group (job_group)"})
public class XxlJobInfo extends IdModel implements IEnumToDbDbId {

    @Schema(description = "执行器主键ID", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer jobGroup;

    @Schema(description = "任务描述", requiredMode = Schema.RequiredMode.REQUIRED)
    private String jobDesc;

    @Schema(description = "作者")
    private String author;

    @Schema(description = "报警邮件")
    private String alarmEmail;

    @Schema(description = "调度类型", requiredMode = Schema.RequiredMode.REQUIRED)
//    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumScheduleType scheduleType;

    @Schema(description = "调度配置，值含义取决于调度类型")
    private String scheduleConf;

    @Schema(description = "调度过期策略", requiredMode = Schema.RequiredMode.REQUIRED)
//    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumMisfireStrategy misfireStrategy;

    @Schema(description = "执行器路由策略")
//    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumExecutorRouteStrategy executorRouteStrategy;

    @Schema(description = "执行器任务handler")
    private String executorHandler;

    @Schema(description = "执行器任务参数")
    private String executorParam;

    @Schema(description = "阻塞处理策略")
//    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumExecutorBlockStrategy executorBlockStrategy;

    @Schema(description = "任务执行超时时间，单位秒", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer executorTimeout;

    @Schema(description = "失败重试次数", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer executorFailRetryCount;

    @Schema(description = "GLUE类型", requiredMode = Schema.RequiredMode.REQUIRED)
//    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumGlueType glueType;

    @Schema(description = "GLUE源代码")
    private String glueSource;

    @Schema(description = "GLUE备注")
    private String glueRemark;

    @Schema(description = "GLUE更新时间")
    private LocalDateTime glueUpdatetime;

    @Schema(description = "子任务ID，多个逗号分隔")
    private String childJobid;

    @Schema(description = "调度状态：0-停止，1-运行", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer triggerStatus;

    @Schema(description = "上次调度时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @JTDField(defaultValue = "0")
    private Long triggerLastTime;

    @Schema(description = "下次调度时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @JTDField(defaultValue = "0")
    private Long triggerNextTime;

    @Schema(description = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime addTime;

    @Schema(description = "更新时间")
    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime updateTime;
}
